/** 
 * Project Name: farm-core 
 * File Name: ProjectionMetrics.java 
 * Package Name: com.bugull.farm.core.frame.pool
 * Date: 2017年3月9日下午7:39:48 
 * Copyright (c) 2017, hadlinks All Rights Reserved. 
 * 
 */
package com.bugull.farm.core.frame.pool;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import com.codahale.metrics.Slf4jReporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;

/** 
 * ClassName: ProjectionMetrics 
 * Function: TODO ADD FUNCTION.  
 * date: 2017年3月9日 下午7:39:48  
 * 
 * @author songwei (songw@hadlinks.com)
 * @version 
 * @since JDK 1.8 
 */
public class ProjectionMetrics {

	private final Logger logger = LoggerFactory.getLogger("MyLogger");
	
    private final Histogram latencyHist;

    ProjectionMetrics(MetricRegistry metricRegistry) {
        //有多种reporter来满足实际需求，还可以导出成cvs
        //控制台reporter
        final ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).build();
        //日志文件reporter
//        final Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry).build();
        //定义reporter的输出频率
        reporter.start(5, TimeUnit.SECONDS);
        latencyHist = metricRegistry.histogram(MetricRegistry.name("任务潜在执行时间统计报表："));
    }

    /**
     * 计算任务潜在执行时间
     * @param duration
     */
    void latency(Duration duration) {
        latencyHist.update(duration.toMillis());
    }
}
